//介绍与评论切换
$('#titleType > li').on('touchstart', function() {
	$(this).addClass('show').siblings().removeClass('show');
	var index = $(this).index();
	$('#content > li').eq(index).addClass('show').siblings().removeClass('show');
});

//章节切换
$('#course h5').on('click', function() {
	$(this).addClass('sl').siblings().removeClass('sl');
});

//点击图片播放视频
$('#videoImg').on('touchstart', function() {
	$(this).hide();
	var video = document.getElementsByTagName('video')[0];
	video.play()
});

//点击立即购买
$('#info button').on('click', function() {
	var isBuy = $(this).attr('type');
	if(isBuy == 'button') {
		$('#buyOk').show();
		$(this).attr({
			'class': 'mui-btn mui-btn-outlined',
			'type': 'ok'
		}).html('已购买');
	}
});
$('#buyOk button').on('click', function() {
	$('#buyOk').hide();
});

//长按删除评论
var longTouch = null,
	delLi = null;
$('#comment > ul > li').on('touchstart', function() {
	delLi = $(this);
	$(this).css({
		'background': '#f0f0f0'
	});
	longTouch = setTimeout(function() {
		$('#del').show();
		returnBut();
	}, 1000);
});
$('#comment > ul > li').on('touchend', function() {
	$(this).css({
		'background': '#fafafa'
	});
	clearTimeout(longTouch);
});
$('#del > button').on('touchstart', function() {
	$('#del').hide();
	delLi.remove();
	history.go(-1); //后退之前一页
});

//点击返回键
function returnBut() {
	if(window.history && window.history.pushState) {
		$(window).on('popstate', function() {
			var hashLocation = location.hash;
			var hashSplit = hashLocation.split("#!/");
			var hashName = hashSplit[1];
			if(hashName !== '') {
				var hash = window.location.hash;
				if(hash === '') {
					$('#del').hide();
				}
			}
		});
		window.history.pushState('forward', null, './#forward');
	}
}